package Data::Conveyor::Ticket::Payload::Instruction::Container;
# ptags: DCTPIC

# $Id: Container.pm 11574 2006-06-06 13:33:47Z gr $

use warnings;
use strict;


our $VERSION = '0.02';


use base qw(
    Data::Container
    Class::Scaffold::Storable
);


sub check {
    my ($self, $exception_container, $ticket) = @_;
    $_->check($exception_container, $ticket) for $self->items;
}


sub get_item_by_type {
    my ($self, $type) = @_;
    for my $instruction ($self->items) {
        return $instruction if $instruction->type eq $type;
    }
    undef;
}


# apply_fields_to_object() only handles single values; if you expect a list,
# use this method and apply the instructions yourself.

sub get_items_of_type {
    my ($self, $type) = @_;
    my @retval = grep { $_->type eq $type } $self->items;
    wantarray ? @retval : \@retval;
}



sub apply_fields_to_object {
    my ($self, $object, %field_map) = @_;
    while (my ($type, $field) = each %field_map) {
        my $instruction = $self->get_item_by_type($type);
        next unless defined $instruction;
        $object->$field($instruction->value);
    }
}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - stage-based conveyor-belt-like ticket handling system

=head1 SYNOPSIS

    {% p.package %}->new;

=head1 DESCRIPTION

None yet. This is an early release; fully functional, but undocumented. The
next release will have more documentation.

=head1 METHODS

=over 4

{% p.write_methods %}

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

